package com.hmall.api.config;

import com.hmall.common.utils.UserContext;
import feign.Logger;
import feign.RequestInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DefaultFeignConfig {
    @Bean
    public Logger.Level feignLogLevel(){
        return Logger.Level.FULL;
    }

    @Bean
    public RequestInterceptor userInfoRequestInterceptor() {
        return template -> {
            Long user = UserContext.getUser();
            log.info("在发起0penFeign调用之前，从ThreadLocal上获取用户ID:{}", user);
            if (user == null) {
                return;
            }
            template.header("user-info", user.toString());
        };
    }
}